package org.batch.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 数据填充
 * 默认实现策略：如果属性有值则不覆盖,如果填充值为null则不填充
 *
 * @author LiKun
 * @date 2021/9/28 14:56
 */
@Component
public class TradingMetaObjectHandler implements MetaObjectHandler {

    private static final String MESSAGE = "成功为字段：{}设置值：{}";
    private static final Logger logger = LoggerFactory.getLogger(TradingMetaObjectHandler.class);

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Date::new, Date.class);
        logger.info(MESSAGE, "createTime", metaObject.getValue("createTime"));
    }

    @Override
    public void updateFill(MetaObject metaObject) {

    }

}
